package pers.cz.service.impl;

import pers.cz.business.TestCaseTemplateBusiness;
import pers.cz.model.AutoTestCaseTemplate;
import pers.cz.pub.BeanHelper;
import pers.cz.service.TestCaseTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * @program: PostGirl-panent
 * @description: TestCaseTemplateService
 * @author: Cheng Zhi
 * @create: 2021-11-09 14:45
 **/
@Service
public class TestCaseTemplateServiceImpl implements TestCaseTemplateService {

    @Autowired
    BeanHelper beanHelper;

    @Override
    public List<AutoTestCaseTemplate> selectAllTestCaseTemplateByPage(Integer pageStart, Integer pageLimit) {
        TestCaseTemplateBusiness business = new TestCaseTemplateBusiness();
        business.setMapper(beanHelper);
        return business.queryAllTestCaseTemplateByPage(pageStart, pageLimit);
    }

    @Override
    public Integer queryCountTemplate() {
        TestCaseTemplateBusiness business = new TestCaseTemplateBusiness();
        business.setMapper(beanHelper);
        return business.queryCountTemplate();
    }

    @Override
    public Integer addTestCaseTemplate(AutoTestCaseTemplate autoTestCaseTemplate) {
        TestCaseTemplateBusiness business = new TestCaseTemplateBusiness();
        business.setMapper(beanHelper);
        return business.addTestCaseTemplate(autoTestCaseTemplate);
    }

    @Override
    public Integer updateTestCaseTemplate(AutoTestCaseTemplate autoTestCaseTemplate) {
        TestCaseTemplateBusiness business = new TestCaseTemplateBusiness();
        business.setMapper(beanHelper);
        return business.updateTestCaseTemplate(autoTestCaseTemplate);
    }

    @Override
    public Integer deleteTestCaseTemplate(Integer id) {
        TestCaseTemplateBusiness business = new TestCaseTemplateBusiness();
        business.setMapper(beanHelper);
        return business.deleteTestCaseTemplate(id);
    }

    @Override
    public List<AutoTestCaseTemplate> selectTestCaseByFuzzy(String testCaseTemplateName, String publicTemplateName) {
        TestCaseTemplateBusiness business = new TestCaseTemplateBusiness();
        business.setMapper(beanHelper);

        return business.selectTestCaseTemplateByFuzzy(testCaseTemplateName, publicTemplateName);
    }

    @Override
    public List<String> selectParamsById(Integer id) {
        TestCaseTemplateBusiness business = new TestCaseTemplateBusiness();
        business.setMapper(beanHelper);
        return business.selectParamsById(id);
    }

    @Override
    public int upload(MultipartFile file, int userId) {

        TestCaseTemplateBusiness business = new TestCaseTemplateBusiness();
        business.setMapper(beanHelper);
        try {
            return business.upload(file, userId);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return 0;
    }
}
